assume cs:codesg,ds:data,ss:stack
data segment
	db 16 dup(0)
data ends

stack segment
	dw 32 dup(0)
stack ends

codesg segment
start:	mov ax,data
	mov ds,ax
	mov ax,stack
	mov ss,ax
	mov sp,20h
	mov ax,12666
	mov si,0
	call dtoc

	mov dh,8
	mov dl,3
	mov cl,2
	call show_str

	mov ax,4c00h
	int 21h

	;convert the word type data to decimal string end with 0  
	;ax: the word type data
	;ds:si the start pointer of the string
dtoc:
	push ax
	push si
	push cx
	push dx
div10:	
	mov cx,0ah
	mov dx,0
	call divdw
	add cx,30h
	mov [si],cl
	inc si
	mov cx,dx
	jcxz d2
	jmp div10
d2:	mov cx,ax
	jcxz end_div10
	jmp div10
end_div10:	
	mov byte ptr [si],0
	mov cx,si
	pop si
	call reverse_str
	pop dx
	pop cx
	pop ax
	ret

	;reverse the decimal string
	;ds:si the pointer of string
	;cx the length of string
reverse_str:
	push si
	push di
	push ax
	push cx
	mov di,cx
	dec di
	mov ax,cx
	mov cx,2
	div cl
	mov cl,al
exchange:
	mov al,[si]
	mov ah,[di]
	mov [si],ah
	mov [di],al
	inc si
	dec di
	loop exchange
	pop cx
	pop ax
	pop di
	pop si
	ret

	
	;Show the string end with '0' on screen at the indicated row and coloum  in specific color 
	;dh: row num which between 0 and 24
	;dl: coloum num which between 0 and 79
	;cl: font and background color
	;ds:si the pointer of string to be showed
show_str:
	push es
	push bp
	push si
	push dx

	;set the row num
	mov al,0ah
	mul dh
	add ax,0b800h
	mov es,ax
	;set the coloum num
	mov al,2
	mul dl
	mov bp,ax
	mov dl,cl
	mov ch,0
to_buffer:
	mov cl,ds:[si]
	jcxz end_show_str
	mov es:[bp],cl
	mov es:[bp].1,dl
	add bp,2
	inc si
	jmp to_buffer
end_show_str:
	pop dx
	pop si
	pop bp
	pop es
	ret

divdw:
	push bp
	sub sp,4
	mov bp,sp
	
	mov [bp],ax
	mov ax,dx
	mov dx,0
	div cx
	mov [bp].2,ax
	mov ax,[bp]
	div cx
	mov cx,dx
	mov dx,[bp].2
	add sp,4
	pop bp
	ret

codesg ends
end start